package com.cssw.fyzb.busi.api.video;

import com.cssw.fyzb.core.model.vo.video.LikeVideoVo;
import com.cssw.fyzb.core.model.vo.video.VideoCommentVo;
import com.cssw.fyzb.busi.service.video.VideoService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 查询喜欢的视频列表
 *
 * @author YangYiQun
 */
@Function(description = "查询视频评论列表", parameters = {
        @Parameter(name = "videoId", type = Type.Integer, description = "视频标识", required = true),
        @Parameter(name = "pageNumber", type = Type.Integer, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.Integer, description = "页大小", required = true),
}, result = @Result(
        properties = {
                @Property(name = "total", type = Type.Integer, description = "总页数"),
                @Property(name = "count", type = Type.Integer, description = "总行数"),

        },
        listProperties = {
                @ListProperty(name = "list", properties = {
                        @Property(name = "userId", type = Type.Integer, description = "用户标识"),
                        @Property(name = "nickName", type = Type.String, description = "昵称"),
                        @Property(name = "avatar", type = Type.String, description = "头像"),
                        @Property(name = "videoId", type = Type.Integer, description = "视频标识"),
                        @Property(name = "commentId", type = Type.Integer, description = "评论标识"),
                        @Property(name = "content", type = Type.String, description = "评论内容"),
                        @Property(name = "type", type = Type.String, description = "评论类型（0-第一层评论 1-回复评论 2-回复回复的评论）"),
                        @Property(name = "likes", type = Type.Integer, description = "点赞数"),
                        @Property(name = "replys", type = Type.Integer, description = "回复评论数"),
                        @Property(name = "replyCommentId", type = Type.String, description = "回复评论标识"),
                        @Property(name = "toUserId", type = Type.String, description = "回复用户标识"),
                        @Property(name = "toNickName", type = Type.String, description = "回复用户昵称"),
                        @Property(name = "createTime", type = Type.String, description = "评论时间"),
                })
        }
))
@Component
public class ListVideoComment implements Action {

    @Autowired
    private VideoService videoService;

    private static final Logger logger = LoggerFactory.getLogger(ListVideoComment.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long videoId = request.getLong("videoId");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        try {
            Page<VideoCommentVo> page = videoService.pageVideoComment(videoId, pageNumber, pageSize);
            return Response.success().put("list", page.getList()).put("total", page.getTotalPage()).put("count", page.getTotalRow());
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
